﻿// Decompiled with JetBrains decompiler
// Type: YJM_PTO.Form1
// Assembly: YJM_PTO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 17EE8669-AD07-48C9-A340-87C7401F98C3
// Assembly location: C:\Users\Administrator\Desktop\bin\YJM_PTO.exe

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;


namespace YJM_PTO
{
  public class Form1 : Form
  {
    private string[] CusArray;
    private IContainer components = (IContainer) null;
    private Button SelectFile;
    private Label label1;
    private TextBox txtCusFilePath;
    private Button btnUpdateCus;
    private TextBox txtQryInfo;
    private Label label2;
    private Button bntQryCus;
    private Label label3;
    private Label lblCusNum;
    private Panel panel1;
    private Panel panel2;
    private DataGridView dgvCusList;
    private DataGridViewTextBoxColumn Column1;
    private DataGridViewTextBoxColumn CodeNo;
    private DataGridViewTextBoxColumn CusName;
    private DataGridViewTextBoxColumn dName;
    private Panel panel3;

        public Form1() => this.InitializeComponent();

        private void Form1_Load(object sender, EventArgs e) => this.LoadCus();

    private void SelectFile_Click(object sender, EventArgs e)
    {
      string str = string.Empty;
      OpenFileDialog openFileDialog1 = new OpenFileDialog();
      openFileDialog1.Filter = "Files(*.txt) | *.txt";
      OpenFileDialog openFileDialog2 = openFileDialog1;
      if (openFileDialog2.ShowDialog() == DialogResult.OK)
        str = openFileDialog2.FileName;
      this.txtCusFilePath.Text = str;
    }

    private void btnUpdateCus_Click(object sender, EventArgs e)
    {
      string fileName = this.txtCusFilePath.Text.Trim();
      if (string.IsNullOrEmpty(fileName))
      {
        int num1 = (int) MessageBox.Show("请确保文件选择正确：客户文件路径不能为空！！");
      }
      else
      {
        string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "CusFile";
        string str1 = path + "\\Customers.txt";
        if (!Directory.Exists(path))
          Directory.CreateDirectory(path);
        if (File.Exists(str1))
        {
          string str2 = "Customers_" + DateTime.Now.ToString("yyMMddHHmmss") + ".txt";
          File.Move(str1, path + "\\" + str2);
        }
        new FileInfo(fileName).CopyTo(str1, true);
        int num2 = (int) MessageBox.Show("客户信息文件上传成功！！");
        this.LoadCus();
      }
    }

    public void LoadCus()
    {
            new Thread(new ThreadStart(() =>
            {
                // 在这里执行您的操作
                // 请注意，Lambda表达式中不再需要显式转换为委托类型
                // 如果需要传递参数，可以使用闭包或者使用`ParameterizedThreadStart`委托
                this.Invoke((MethodInvoker)(() =>
                {
                    Cursor.Current = Cursors.WaitCursor;
                    string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "CusFile" + "\\Customers.txt";
                    if (!File.Exists(path))
                        return;
                    this.dgvCusList.Rows.Clear();
                    StreamReader streamReader = new StreamReader(File.Open(path, FileMode.Open), Encoding.GetEncoding("GB2312"));
                    Thread.Sleep(1);
                    this.CusArray = streamReader.ReadToEnd().Replace("\r\n", "\n").Split('\n');
                    foreach (string cus in this.CusArray)
                    {
                        if (!string.IsNullOrEmpty(cus))
                        {
                            string[] strArray = cus.Split(',');
                            int count = this.dgvCusList.Rows.Count;
                            this.dgvCusList.Rows.Insert(count, new DataGridViewRow());
                            this.dgvCusList.Rows[count].Cells[0].Value = (count + 1);
                            this.dgvCusList.Rows[count].Cells[1].Value = strArray[2];
                            this.dgvCusList.Rows[count].Cells[2].Value = strArray[0];
                            this.dgvCusList.Rows[count].Cells[3].Value = strArray[1];
                        }
                    }
                    this.lblCusNum.Text = this.dgvCusList.Rows.Count.ToString();
                    streamReader.Close();
                    streamReader.Dispose();
                    Cursor.Current = Cursors.Default;
                }));
            })).Start();

            //new Thread((ParameterizedThreadStart) (o => this.Invoke((Delegate) (() =>
            //{
            //  Cursor.Current = Cursors.WaitCursor;
            //  string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "CusFile" + "\\Customers.txt";
            //  if (!File.Exists(path))
            //    return;
            //  this.dgvCusList.Rows.Clear();
            //  StreamReader streamReader = new StreamReader((Stream) File.Open(path, FileMode.Open), Encoding.GetEncoding("GB2312"));
            //  Thread.Sleep(1);
            //  this.CusArray = streamReader.ReadToEnd().Replace("\r\n", "\n").Split('\n');
            //  foreach (string cus in this.CusArray)
            //  {
            //    if (!string.IsNullOrEmpty(cus))
            //    {
            //      string[] strArray = cus.Split(',');
            //      int count = this.dgvCusList.Rows.Count;
            //      this.dgvCusList.Rows.Insert(count, new DataGridViewRow());
            //      this.dgvCusList.Rows[count].Cells[0].Value = (object) (count + 1);
            //      this.dgvCusList.Rows[count].Cells[1].Value = (object) strArray[2];
            //      this.dgvCusList.Rows[count].Cells[2].Value = (object) strArray[0];
            //      this.dgvCusList.Rows[count].Cells[3].Value = (object) strArray[1];
            //    }
            //  }
            //  this.lblCusNum.Text = this.dgvCusList.Rows.Count.ToString();
            //  streamReader.Close();
            //  streamReader.Dispose();
            //  Cursor.Current = Cursors.Default;
            //})))).Start();
        }

        private void bntQryCus_Click(object sender, EventArgs e)
    {
      string str1 = this.txtQryInfo.Text.Trim();
      if (string.IsNullOrEmpty(str1))
        this.LoadCus();
      else if (this.CusArray == null)
      {
        int num = (int) MessageBox.Show("请先更新客户信息！");
      }
      else
      {
        List<string> stringList = new List<string>();
        for (int index = 0; index < ((IEnumerable<string>) this.CusArray).Count<string>(); ++index)
        {
          string cus = this.CusArray[index];
          if (cus.Contains(str1))
            stringList.Add(cus);
        }
        this.dgvCusList.Rows.Clear();
        foreach (string str2 in stringList)
        {
          char[] chArray = new char[1]{ ',' };
          string[] strArray = str2.Split(chArray);
          int count = this.dgvCusList.Rows.Count;
          this.dgvCusList.Rows.Insert(count, new DataGridViewRow());
          this.dgvCusList.Rows[count].Cells[0].Value = (object) (count + 1);
          this.dgvCusList.Rows[count].Cells[1].Value = (object) strArray[2];
          this.dgvCusList.Rows[count].Cells[2].Value = (object) strArray[0];
          this.dgvCusList.Rows[count].Cells[3].Value = (object) strArray[1];
        }
        this.lblCusNum.Text = this.dgvCusList.Rows.Count.ToString();
      }
    }

    protected override void Dispose(bool disposing)
    {
      if (disposing && this.components != null)
        this.components.Dispose();
      base.Dispose(disposing);
    }

    private void InitializeComponent()
    {
      this.SelectFile = new Button();
      this.label1 = new Label();
      this.txtCusFilePath = new TextBox();
      this.btnUpdateCus = new Button();
      this.txtQryInfo = new TextBox();
      this.label2 = new Label();
      this.bntQryCus = new Button();
      this.label3 = new Label();
      this.lblCusNum = new Label();
      this.panel1 = new Panel();
      this.panel2 = new Panel();
      this.dgvCusList = new DataGridView();
      this.Column1 = new DataGridViewTextBoxColumn();
      this.CodeNo = new DataGridViewTextBoxColumn();
      this.CusName = new DataGridViewTextBoxColumn();
      this.dName = new DataGridViewTextBoxColumn();
      this.panel3 = new Panel();
      this.panel1.SuspendLayout();
      this.panel2.SuspendLayout();
      ((ISupportInitialize) this.dgvCusList).BeginInit();
      this.panel3.SuspendLayout();
      this.SuspendLayout();
      this.SelectFile.Location = new Point(530, 72);
      this.SelectFile.Name = "SelectFile";
      this.SelectFile.Size = new Size(75, 29);
      this.SelectFile.TabIndex = 0;
      this.SelectFile.Text = "选择";
      this.SelectFile.UseVisualStyleBackColor = true;
      this.SelectFile.Click += new EventHandler(this.SelectFile_Click);
      this.label1.AutoSize = true;
      this.label1.Location = new Point(12, 78);
      this.label1.Name = "label1";
      this.label1.Size = new Size(82, 15);
      this.label1.TabIndex = 1;
      this.label1.Text = "客户文件：";
      this.txtCusFilePath.Location = new Point(100, 75);
      this.txtCusFilePath.Name = "txtCusFilePath";
      this.txtCusFilePath.ReadOnly = true;
      this.txtCusFilePath.Size = new Size(410, 25);
      this.txtCusFilePath.TabIndex = 2;
      this.btnUpdateCus.Location = new Point(613, 72);
      this.btnUpdateCus.Name = "btnUpdateCus";
      this.btnUpdateCus.Size = new Size(75, 29);
      this.btnUpdateCus.TabIndex = 3;
      this.btnUpdateCus.Text = "上传";
      this.btnUpdateCus.UseVisualStyleBackColor = true;
      this.btnUpdateCus.Click += new EventHandler(this.btnUpdateCus_Click);
      this.txtQryInfo.Location = new Point(100, 20);
      this.txtQryInfo.Name = "txtQryInfo";
      this.txtQryInfo.Size = new Size(410, 25);
      this.txtQryInfo.TabIndex = 14;
      this.label2.AutoSize = true;
      this.label2.Location = new Point(12, 23);
      this.label2.Name = "label2";
      this.label2.Size = new Size(82, 15);
      this.label2.TabIndex = 13;
      this.label2.Text = "客户信息：";
      this.bntQryCus.Location = new Point(530, 20);
      this.bntQryCus.Name = "bntQryCus";
      this.bntQryCus.Size = new Size(75, 29);
      this.bntQryCus.TabIndex = 15;
      this.bntQryCus.Text = "查询";
      this.bntQryCus.UseVisualStyleBackColor = true;
      this.bntQryCus.Click += new EventHandler(this.bntQryCus_Click);
      this.label3.AutoSize = true;
      this.label3.Location = new Point(3, 9);
      this.label3.Name = "label3";
      this.label3.Size = new Size(82, 15);
      this.label3.TabIndex = 16;
      this.label3.Text = "客户数量：";
      this.lblCusNum.AutoSize = true;
      this.lblCusNum.Location = new Point(91, 9);
      this.lblCusNum.Name = "lblCusNum";
      this.lblCusNum.Size = new Size(15, 15);
      this.lblCusNum.TabIndex = 17;
      this.lblCusNum.Text = "0";
      this.panel1.Controls.Add((Control) this.txtQryInfo);
      this.panel1.Controls.Add((Control) this.SelectFile);
      this.panel1.Controls.Add((Control) this.label1);
      this.panel1.Controls.Add((Control) this.bntQryCus);
      this.panel1.Controls.Add((Control) this.txtCusFilePath);
      this.panel1.Controls.Add((Control) this.btnUpdateCus);
      this.panel1.Controls.Add((Control) this.label2);
      this.panel1.Dock = DockStyle.Top;
      this.panel1.Location = new Point(0, 0);
      this.panel1.Name = "panel1";
      this.panel1.Size = new Size(1223, 130);
      this.panel1.TabIndex = 18;
      this.panel2.Controls.Add((Control) this.dgvCusList);
      this.panel2.Controls.Add((Control) this.panel3);
      this.panel2.Dock = DockStyle.Fill;
      this.panel2.Location = new Point(0, 130);
      this.panel2.Name = "panel2";
      this.panel2.Size = new Size(1223, 554);
      this.panel2.TabIndex = 19;
      this.dgvCusList.AllowUserToAddRows = false;
      this.dgvCusList.AllowUserToDeleteRows = false;
      this.dgvCusList.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
      this.dgvCusList.BackgroundColor = Color.Honeydew;
      this.dgvCusList.BorderStyle = BorderStyle.None;
      this.dgvCusList.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
      this.dgvCusList.Columns.AddRange((DataGridViewColumn) this.Column1, (DataGridViewColumn) this.CodeNo, (DataGridViewColumn) this.CusName, (DataGridViewColumn) this.dName);
      this.dgvCusList.Dock = DockStyle.Fill;
      this.dgvCusList.GridColor = Color.Honeydew;
      this.dgvCusList.Location = new Point(0, 33);
      this.dgvCusList.Margin = new Padding(4);
      this.dgvCusList.MultiSelect = false;
      this.dgvCusList.Name = "dgvCusList";
      this.dgvCusList.ReadOnly = true;
      this.dgvCusList.RowTemplate.Height = 23;
      this.dgvCusList.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
      this.dgvCusList.Size = new Size(1223, 521);
      this.dgvCusList.TabIndex = 19;
      this.dgvCusList.Tag = (object) "dgvStopDevList";
      this.Column1.FillWeight = 30.79317f;
      this.Column1.HeaderText = "序号";
      this.Column1.Name = "Column1";
      this.Column1.ReadOnly = true;
      this.CodeNo.FillWeight = 73.92893f;
      this.CodeNo.HeaderText = "编号";
      this.CodeNo.Name = "CodeNo";
      this.CodeNo.ReadOnly = true;
      this.CusName.FillWeight = 162.4366f;
      this.CusName.HeaderText = "客户名称";
      this.CusName.Name = "CusName";
      this.CusName.ReadOnly = true;
      this.dName.FillWeight = 132.8413f;
      this.dName.HeaderText = "名称首字母";
      this.dName.Name = "dName";
      this.dName.ReadOnly = true;
      this.panel3.Controls.Add((Control) this.label3);
      this.panel3.Controls.Add((Control) this.lblCusNum);
      this.panel3.Dock = DockStyle.Top;
      this.panel3.Location = new Point(0, 0);
      this.panel3.Name = "panel3";
      this.panel3.Size = new Size(1223, 33);
      this.panel3.TabIndex = 18;
      this.AutoScaleDimensions = new SizeF(8f, 15f);
      this.AutoScaleMode = AutoScaleMode.Font;
      this.ClientSize = new Size(1223, 684);
      this.Controls.Add((Control) this.panel2);
      this.Controls.Add((Control) this.panel1);
      this.MaximizeBox = false;
      this.Name = "Form1";
      this.StartPosition = FormStartPosition.CenterParent;
      this.Text = "Form1";
      this.Load += new EventHandler(this.Form1_Load);
      this.panel1.ResumeLayout(false);
      this.panel1.PerformLayout();
      this.panel2.ResumeLayout(false);
      ((ISupportInitialize) this.dgvCusList).EndInit();
      this.panel3.ResumeLayout(false);
      this.panel3.PerformLayout();
      this.ResumeLayout(false);
    }
  }
}
